package com.salts.controller;

import com.salts.domain.dto.ClothDto;
import com.salts.domain.dto.Result;
import com.salts.domain.vo.*;
import com.salts.service.HomePageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 首页接口 /home
 */
@RestController
@RequestMapping("/home")
public class HomePageController {
    @Autowired
    HomePageService homePageService;

    /**
     * 轮播图接口 /wheelcast -Get
     */
    @RequestMapping("/wheelcast")
    //List<CastVo> wheelCast(){
    List<Map<String,String>> wheelCast(){
        List<Map<String,String>> returnMap = new ArrayList<>();
        for (int i = 0 ;i<5 ; i++){
            HashMap<String, String> param = new HashMap<>();
            param.put("picName", String.valueOf(i));
            param.put("imgUrl","http://www.salts-cloth.com.cn/img/"+i+".png");
            returnMap.add(param);
        }
        return returnMap;
                //homePageService.wheelCast();
    }

    /**
     * 店主推荐商品接口 /recommended -Get
     */
    @RequestMapping("/recommended")
    String recommendedProduct(){

        try {
            return homePageService.recommendedProduct();
        } catch (IOException e) {
            return "{\"请求失败!\":\"后台出现错误\"}";
        }
    }

    /**
     * 热门商品接口 /hotproduct -Get
     * @return [
     *     {
     *         "clothId": 5,
     *         "clothName": "测试品5号",
     *         "price": 88.880,
     *         "comment": null,
     *         "imageUrl": null
     *     }
     * ]
     */
    @RequestMapping("/hotproduct")
    List<DisplayClothVo> hotProduct(Integer userId){
        if (userId==null){
            userId=0;
        }
        return homePageService.hotProduct(userId);
    }

    /**
     * 商品详情接口 /productdetail -Get
     * @param clothId
     */
    @RequestMapping("/productdetail")
    ClothVo productDetail(int clothId){
        ClothVo clothVos = homePageService.productDetail(clothId);
        return clothVos;
    }

    /**
     * @param clothDto
     * {
     *     "clothId":5,
     *     "colorId":1,
     *     "specId":4
     * }
     *
     * @return {
     *     "success": true,
     *     "errorMsg": null,
     *     "data": 30,
     *     "total": null
     * }
     */
    @RequestMapping("/queryStock")
    Result productDetailStock(@RequestBody ClothDto clothDto){
        return Result.ok(homePageService.stockNumberQuery(clothDto));
    }

    /**
     * 上新商品一览接口：/newproduct -Get
     */
    @RequestMapping("/newproduct")
    List<DisplayClothVo> newProductDisplay(){
        return homePageService.newProductDisplay();
    }

    /**
     * @return 展示全部套餐接口
     */
    @RequestMapping("/combo")
    List<DisplayComboVo> promotionalProduct(){
        return homePageService.promotionalProduct();
    }

    /**
     * 浏览套餐概要接口
     * @return
     */
    @RequestMapping("/promotionalFullInfo")
    List<DisplayComboVo> promotionalFullInfo(){
        return homePageService.promotionalFullInfo();
    }

    /**
     * @param comboId
     * @return
     */
    @RequestMapping("/promotionalDetail")
    ComboVo promotionalDetail(int comboId){
        return homePageService.promotionalDetail(comboId);
    }


}
